package com.flyme.excel.validator;

import com.ycc.vins.excel.ExcelCellValidator;
import com.ycc.vins.util.ValidateResult;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Nullable;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by lijizhong on 2017/12/15.
 */
@Service
public class LegalFrameNoValidator implements ExcelCellValidator {

    final Pattern p = Pattern.compile("^[0-9A-Za-z]{17}$");
/*
    @Autowired
    private CommonService commonService;*/

    @Nullable
    @Override
    public ValidateResult apply(String s) {
        if (StringUtils.isBlank(s)) {
            return ValidateResult.pass();
        }
        /*List<Vehicle> vehicles = commonService.listByFrameNoSet(Sets.newHashSet(s));
        if (CollectionUtils.isEmpty(vehicles)) {
            return ValidateResult.notPass("不存在！");
        } else {
            return ValidateResult.pass();
        }*/
        Matcher m = p.matcher(s);
        if (!m.find()) {
            return ValidateResult.notPass("格式不正确(正确的为字母和数字，17位)");
        }
        return ValidateResult.pass();
    }
}
